const tool = require('../tools/tool')

module.exports = {
    getList: {
        exp: '获取类别列表',
        method: 'get',
        auth: true,
        async func(data) {
            if (data.query.withPaper) {
                let re = await tool.methods.category().getList()
                for (let i = 0; i < re.length; i++) {
                    re[i].paperList = await tool.methods.paper().getList.byCategory(re[i].id)
                }
                return re
            }
            return await tool.methods.category().getList()
        }
    },
    add: {
        exp: '添加类别',
        method: 'post',
        auth: {
            admin: true,
        },
        async func(data) {
            await tool.methods.category().add(data.param.name)
        }
    },
    update: {
        exp: '更新类别名称',
        method: 'post',
        auth: {
            admin: true,
        },
        async func(data) {
            await tool.methods.category().update(data.param.id, data.param.name)
        }
    },
    delete: {
        exp: '删除类别',
        method: 'post',
        auth: {
            admin: true
        },
        async func(data) {
            await tool.methods.category().delete(data.param.id)
        }
    }
}